#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "n2base.h"
#include "n2x86asm.h"

int is_ins(const char* ins_name, size_t length, const TAsxInsTable** ppInsTab)
{
    const int MAX_INS_LENGTH = 14;
    unsigned int hash, pos;
    unsigned int htblsize;
    const TAsxInsFind* idxlist, *find;
    int i;

    if (length > MAX_INS_LENGTH)
        return 0;
    unsigned char insstr[MAX_INS_LENGTH+2];
    i = 0;
    while(ins_name[i] && i < MAX_INS_LENGTH) {
        if (ins_name[i] >= 'A' && ins_name[i] <= 'Z')
            insstr[i] = ins_name[i] + ('a' - 'A');
        else
            insstr[i] = ins_name[i];
        i++;
    }
    insstr[i] = 0;

    hash = crc32_hash(insstr, strlen((const char*)insstr));
    htblsize = (unsigned)GetX86InsHashSize();
    pos = hash % htblsize;

    idxlist = ins_hashtbl[pos];
    if ( ! idxlist )
        return 0;
    i = 0;
    find = &idxlist[i];
    do
    {
        if (find->hash == hash && 0==asx_stricmp(ins_tab[find->index].ins, ins_name))
        {
            if (ppInsTab)
                *ppInsTab = & ins_tab[find->index];
            return 1;
        }
        i++;
        find = &idxlist[i];
    }while (find->hash != 0 && find->index != 0xffffffff);
    return 0;
}













